home *** CD-ROM | disk | FTP | other *** search
- #if PIGS_SHELL_PRINT
-
- #include <Types.h>
-
- #include "appGlobals.h"
- #include "appPrint.h"
- #include "appMenus.h"
- #include "appErrors.h"
- #include "appAEvts.h"
-
- #include "qdPrintUtils.h"
-
- #include "cursorUtils.h"
-
- #include "win.h"
- #include "winTables.h"
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTION PROTOTYPES
- |**| ==============================================================================
- \**/
- void AdjustMenusForPrinting ( void ) ;
-
-
- /**\
- |**| ==============================================================================
- |**| PUBLIC FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- DoAppPageSetupCommand
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- void DoAppPageSetupCommand ( winHandle win )
- {
- OSErr err ;
- FSSpec spec = {0,0,"\p"} ;
-
- if ( win==nil) return ;
- err = DoAppGetPrintStrutures( win ) ; // make sure that we have the needed print structures
- WarnIfErr( err ) ;
- if ( err ) return ;
-
- HiliteMenu(0) ; // Unhighlight whatever MenuSelect or MenuKey hilited
- AdjustMenusForPrinting() ;
-
- err = QDStyleDlog( GetWinPrintRec(win) ) ;// do the classic page setup dialog
-
- spec = GetWinFSSpec( win ) ;
- if (spec.name[0]) // if the win has an associated file
- {
- err = SaveResourceTHPrint( GetWinPrintRec(win), &spec ) ;
- }
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoAppPrintCommand
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- void DoAppPrintCommand ( winHandle win )
- {
- OSErr err ;
- FSSpec spec = {0,0,"\p"} ;
-
- if ( win==nil) return ;
- err = DoAppGetPrintStrutures( win ) ; // make sure that we have the needed print structures
- WarnIfErr( err ) ;
- if ( err ) return ;
-
- HiliteMenu(0) ; // Unhighlight whatever MenuSelect or MenuKey hilited
- AdjustMenusForPrinting() ;
-
- err = QDJobDlog( GetWinPrintRec(win) ) ; // do the classic page setup dialog
- if (err) return ;
-
- spec = GetWinFSSpec( win ) ;
- if (spec.name[0]) // if the win has an associated file
- {
- err = SaveResourceTHPrint( GetWinPrintRec(win), &spec ) ;
- }
-
- DoAppPrintOneCommand( win ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoAppPrintOneCommand
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- void DoAppPrintOneCommand ( winHandle win )
- {
- OSErr err ;
- FSSpec spec = {0,0,"\p"} ;
-
- if ( win == nil) return ;
- err = DoAppGetPrintStrutures( win ) ; // make sure that we have the needed print structures
- WarnIfErr( err ) ;
- if ( err ) return ;
-
- // we can just issue a print command, because we have a valid print record for the
- // document. This is in the dPrintRec record of the document record, we created
- // it (or read it in from the document's file) at the time we created the window.
- // for more information on this look at the routines SetupPrintHdl() and LoadPHdl()
-
- spec = GetWinFSSpec( win ) ;
-
- if (spec.name[0]) // if the win has an associated file
- SendPDOC( &spec ) ; // send print apple event
- else
- DoAppPrintLoop( win ) ;
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoAppGetPrintStrutures
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- OSErr DoAppGetPrintStrutures ( winHandle win )
- {
- FSSpec spec ;
- THPrint theTHPrint = nil ;
- OSErr err ;
-
- spec = GetWinFSSpec( win ) ;
-
- if ( (err=QDPrinting_available()) == noErr ) // if printing is possible
- {
- if ( GetWinPrintRec(win) ) return noErr ; // we already have it so return
- if (spec.name[0]) // if the win has an associated file
- err = LoadResourceTHPrint( &theTHPrint,&spec) ; // get job from file
- if (theTHPrint==nil) // if didnt get it
- err = GetDefaultTHPrint( &theTHPrint ) ; // get default
- SetWinPrintRec( win, theTHPrint ) ;
- }
- return err ; // return above error
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoAppGetPageSize
- *------------------------------------------------------------------------------*
- \*------------------------------------------------------------------------------*/
- OSErr DoAppGetPageSize ( winHandle win, Rect *pageRect )
- {
- THPrint theTHPrint = nil ;
- OSErr err ;
-
- err = DoAppGetPrintStrutures( win ) ; // make sure that we have the needed print structures
- WarnIfErr( err ) ;
- if ( err ) return err ;
-
- if ( (err=QDPrinting_available()) == noErr ) // if printing is possible
- {
- theTHPrint = GetWinPrintRec(win) ;
- err = QDGetPageSize( theTHPrint, pageRect ) ;
- }
- return err ; // return above error
- }
-
-
- /*------------------------------------------------------------------------------*\
- DoAppPrintLoop
- *------------------------------------------------------------------------------*
- This is a basic GX print loop for QuickDraw-based applications
- For simplicity, we don't implement a facility for the user to select
- different formats for each page. In another app (a word processor
- for example) we may want to do this, in which case the jobFormat field
- of the document record could be implemented as an array with one
- slot in the array for each page in the win, or as a list. We wanted
- to keep this simple...
- \*------------------------------------------------------------------------------*/
- OSErr DoAppPrintLoop ( winHandle win )
- {
- short pageCount ;
- long firstPage, lastPage;
- GrafPtr savedPort ;
- OSErr err ;
-
- err = DoAppGetPrintStrutures( win ) ; // make sure that we have the needed print structures
- WarnIfErr( err ) ;
- if ( err ) return err ;
-
- err = CallWinPageCountProc ( win, &pageCount ) ;
- firstPage = 1; lastPage = pageCount ;
- WarnIfErr( err ) ;
- if ( err ) return err;
-
- SetUpCursors( kWatchACursor ) ;
- GetPort( &savedPort ) ;
-
-
- if ( (err=QDPrinting_available()) == noErr ) // else if printing is possible
- {
- QDPrintLoopParamsRec params ;
-
- params.hPrint = GetWinPrintRec(win) ;
- params.window = GetWinWindow(win) ;
- params.firstPage = firstPage ;
- params.lastPage = lastPage ;
-
- err = QDPrintLoopBegin( ¶ms ) ;
- if (!err)
- {
- for ( params.currentPage = params.firstPage;
- params.currentPage <= params.lastPage && !err ;
- params.currentPage ++ )
- {
- if (!err) err = QDPrintLoopPageBefore( ¶ms ) ;
- if (!err) err = CallWinPagePrintProc( win, params.printingPort, params.currentPage ) ;
- if (!err) err = QDPrintLoopPageAfter( ¶ms ) ;
- }
- err = QDPrintLoopEnd( ¶ms ) ;
- }
- }
-
-
- SetPort( savedPort ) ;
- TearDownCursors( kArrowCursor ) ;
- return err ; // return above error
- }
-
-
- /**\
- |**| ==============================================================================
- |**| PRIVATE FUNCTIONS
- |**| ==============================================================================
- \**/
-
-
- /*------------------------------------------------------------------------------*\
- AdjustMenusForPrinting
- *------------------------------------------------------------------------------*
- This routine enables the Edit menu items so that print dialogs can
- do cut, copy, and paste.
- This routine is called by the menu handling code of any windows that
- support Page Setup or Print commands.
- \*------------------------------------------------------------------------------*/
- static void AdjustMenusForPrinting ( void )
- {
- MenuHandle theMenu ;
-
- // if we are printing, disable everything except the edit menu
-
- dimAllMenus() ;
-
- // do the method menu
- theMenu = GetMenuHandle ( mEdit ) ;
- EnableItem ( theMenu, kWholeMenu ) ;
- EnableItem ( theMenu, iUndo ) ;
- EnableItem ( theMenu, iCut ) ;
- EnableItem ( theMenu, iCopy ) ;
- EnableItem ( theMenu, iPaste ) ;
- EnableItem ( theMenu, iClear ) ;
-
- DrawMenuBar() ;
- }
-
- #endif
-
-
-